import 'package:awak/common/db/db_helper.dart';
import 'package:awak/common/models/room.dart';

class RoomRepository {
  // 新增房间
  Future<int> addRoom(Room room) async {
    final db = await DBHelper.database;
    return await db.insert('room', room.toMap());
  }

  // 获取所有房间
  Future<List<Room>> getAllRooms() async {
    final db = await DBHelper.database;
    final res = await db.query('room');
    return res.map((e) => Room.fromMap(e)).toList();
  }

  // 删除房间
  Future<int> deleteRoom(int id) async {
    final db = await DBHelper.database;
    return await db.delete('room', where: 'id = ?', whereArgs: [id]);
  }

  // 更新房间
  Future<int> updateRoom(Room room) async {
    final db = await DBHelper.database;
    return await db.update('room', room.toMap(), where: 'id = ?', whereArgs: [room.id]);
  }
} 